package clsLib;

import java.util.ArrayList;

/**
*
*
*
*/
public class Cart {
    
	private ArrayList<GoodsItem> carGoodsList = new ArrayList();
	private double allSum=0;
	

	public void add(GoodsItem newItem) {
             
            if(newItem.getNum()==0)
                return;
           
            for (GoodsItem i:carGoodsList) 
		if (i.getGoods().getName().equals(newItem.getGoods().getName())) {
                   i.setNum(i.getNum()+newItem.getNum());
                   
                   i.setItemPrice(i.getGoods().getPrice()*i.getNum());
                   //Item的数量个单价均需要修改
                    return;     
                }
                
		carGoodsList.add(newItem);
  
            }
        
        public void empty(){
            carGoodsList=new ArrayList<GoodsItem>();
            return;
        }

        public ArrayList<GoodsItem> getGoodsList(){
            return carGoodsList;
        }

        
        public double getAllSum(){
            allSum=0;
            for(GoodsItem one:carGoodsList)
                allSum+=one.getItemPrice();
            
            return allSum;
        }


}
